﻿using B.S.Passport.Infacetrue;
using B.S.Passport.Domain;
using B.S.Passport.ErrorCode;
using B.S.Passport.Write.API.Application;
using DAL;
using MediatR;
using Azure.Core;

namespace B.S.Passport.Write.API.ApplicationHander
{
    public class AddWhouseCommandHander : IRequestHandler<AddWhouseCommand, ApiResult<object>>
    {
        public readonly IBaseRepository<WarehouseModel> wbase;
        public readonly DBHelper1 dBHelper;

        public AddWhouseCommandHander(IBaseRepository<WarehouseModel> baseRepository, DBHelper1 dBHelper)
        {
            this.wbase = baseRepository;
            this.dBHelper = dBHelper;
        }

        public Task<ApiResult<object>> Handle(AddWhouseCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult = new ApiResult<object>();
            apiResult.Code = (ApiEnums)Renum.添加成功;
            apiResult.Message = Renum.添加成功.ToString(); 
            var sql = $"insert into WarehouseModel values('{request.WarehouseName}','{request.Defaultnot}','{request.Disable}','{request.WHouseId}','{request.WHouseTypeId}','{request.isdelete}','{request.WarehouseNumber}')";
            var ss = dBHelper.NonQuery(sql);
            if (ss > 0)
            {
                apiResult.Code = (ApiEnums)Renum.添加成功;
                apiResult.Message = Renum.添加成功.ToString();
                return Task.FromResult(apiResult);
            }
            else
            {
                apiResult.Code = (ApiEnums)Renum.添加失败;
                apiResult.Message = Renum.添加失败.ToString();
                return Task.FromResult(apiResult);
            }

        }
    }
}
